"use strict";
cc._RF.push(module, 'c51616iO3tP1ZkY9V015kKp', 'JoyStick');
// Script/JoyStick.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var AppEvent_1 = require("./Core/AppEvent");
var EventManager_1 = require("./Managers/EventManager");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var JoyStick = /** @class */ (function (_super) {
    __extends(JoyStick, _super);
    function JoyStick() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.dotSprite = null;
        _this.startPoint = new cc.Vec2(0, 0);
        return _this;
    }
    JoyStick.prototype.onLoad = function () {
    };
    JoyStick.prototype.onTouchStart = function (event) {
        var location = event.getLocation();
        var winSize = cc.view.getVisibleSize();
        this.node.position = new cc.Vec3(location.x - winSize.width / 2, location.y - winSize.height / 2, 0);
        this.startPoint = location;
    };
    JoyStick.prototype.onTouchMove = function (event) {
        var location = event.getLocation();
        var offsetX = location.x - this.startPoint.x;
        var offsetY = location.y - this.startPoint.y;
        var contentSize = this.node.getContentSize();
        var length = location.sub(cc.v2(this.startPoint)).mag();
        var p = location.sub(cc.v2(this.startPoint)).normalize();
        var radius = contentSize.width / 2;
        if (length <= radius) {
            this.dotSprite.position = new cc.Vec3(offsetX, offsetY, 0);
        }
        else {
            this.dotSprite.position = new cc.Vec3(radius * p.x, radius * p.y, 0);
        }
        EventManager_1.dispatchEvent(AppEvent_1.EVT_PLAYER_SET_P, { p: p });
        // if(offsetX > radius){
        //     offsetX = radius
        // }else if(offsetX < -radius){
        //     offsetX = -radius
        // }
        // if(offsetY > radius){
        //     offsetY = radius
        // }else if(offsetY < -radius){
        //     offsetY = -radius
        // }
    };
    JoyStick.prototype.onTouchEnd = function (event) {
        this.dotSprite.position = cc.Vec3.ZERO;
        EventManager_1.dispatchEvent(AppEvent_1.EVT_PLAYER_SET_P, { p: cc.v3(0, 0, 0) });
    };
    __decorate([
        property(cc.Node)
    ], JoyStick.prototype, "dotSprite", void 0);
    JoyStick = __decorate([
        ccclass
    ], JoyStick);
    return JoyStick;
}(cc.Component));
exports.default = JoyStick;

cc._RF.pop();